import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    searchFlag: false,
    loginFlag: false,
    registerFlag: false,
    forgetFlag: false,
    emailFlag: false,
    drawer: false,
    loginUrl: "",
    userId: null,
    avatar: null,
    nickname: null,
    intro: null,
    webSite: null,
    loginType: null,
    email: null,
    token: null,
    dialogFormVisible:false,
    articleLikeSet: [],
    commentLikeSet: [],
    blogInfo: {
      articleTypes:[],
      basicInfo:{
        webName: "小徐",
        browseNum: 65,
        webICP: "皖ICP备2021018143号-1",
        webStatement: "Copyright©2021~2023 www.xqijun.top All Rights Reserved",
        webCreateTime: "2022-01-05T07:54:53.000+00:00",
        aboutMe: "测试",
        intro: '简介',
      },
      pageInfo:[],
      friendInfo:[],
      authorInfo:{
        id: 1,
        introduction: "",
        nickName: "Xx",
        qq: '',
        avatar: "https://portrait.gitee.com/uploads/avatars/user/3339/10018694_xxNice_1642293539.png!avatar60",
        email: "xuqijun@xqijun.top",
        sex: 0,
        remark: "aaaa",
        giteeAddress: "https://gitee.com/xxNice",
        githubAddress: "https://gitee.com/xxNice"
      },
      noticeInfo: {
        id: 1,
        noticeTitle: "通知测试",
        content: "tztztztztz",
        createTime: "2023-02-13T07:29:37.000+00:00",
        userId: 1,
        userName: "xx",
        state: 1
      },
      countNum:{
        articleCount: 1,
        tagCount: 1,
        msgCount: 0
      }
    }
  },
  mutations: {
    saveLoginUrl(state, url) {
      state.loginUrl = url;
    },
    saveEmail(state, email) {
      state.email = email;
    },
    updateUserInfo(state, user) {
      state.nickname = user.nickname;
      state.intro = user.intro;
      state.webSite = user.webSite;
    },
    savePageInfo(state, pageList) {
      state.pageList = pageList;
    },
    updateAvatar(state, avatar) {
      state.avatar = avatar;
    },
    updateBlogInfo(state, blogInfo) {
      state.blogInfo = blogInfo;
    },
    closeModel(state) {
      state.registerFlag = false;
      state.loginFlag = false;
      state.searchFlag = false;
      state.emailFlag = false;
    },
    articleLike(state, articleId) {
      var articleLikeSet = state.articleLikeSet;
      if (articleLikeSet.indexOf(articleId) != -1) {
        articleLikeSet.splice(articleLikeSet.indexOf(articleId), 1);
      } else {
        articleLikeSet.push(articleId);
      }
    },
    commentLike(state, commentId) {
      var commentLikeSet = state.commentLikeSet;
      if (commentLikeSet.indexOf(commentId) != -1) {
        commentLikeSet.splice(commentLikeSet.indexOf(commentId), 1);
      } else {
        commentLikeSet.push(commentId);
      }
    },
    setDialogFormVisible(state) {
      state.dialogFormVisible = !state.dialogFormVisible;
    }
  },
  actions: {},
  modules: {},
  plugins: [
    createPersistedState({
      storage: window.sessionStorage
    })
  ]
});
